package com.zyd.blog.controller;

import java.util.Arrays;
import java.util.Optional;

public enum ResCode{
	
		SUCCESS(0,"上传成功"),
		NO_RESULTS(5000,"无解析结果"),
		NOT_SUPPORT(6000,"	暂不支持该功能"),
		PARAM_ERROR(4000,"请求参数格式错误"),
		ENCRYPTION_ERROR(4001,"加密方式错误"),
		NO_AUTH(4002,"无功能权限"),
		REQUEST_LIMIT(4003,"该apikey没有可用请求次数"),
		NO_AUTH2(4005,"无功能权限"),
		APIKEY_ERROR(4007,"apikey不合法"),
		USERID_ERROR(4100,"userid获取失败"),
		UPLOAD_ERROR(4200,"上传格式错误"),
		BATCH_LIMIT(4300,"批量操作超过限制"),
		NO_USERID(4400,"没有上传合法userid"),
		USERID_LIMIT(4500,"userid申请个数超过限制"),
		INPUT_EMPTY(4600,"输入内容为空"),
		INPUT_TOO_LANG(4602,"输入文本内容超长(上限150)"),
		UPLOAD_FAILURE(7002,"上传信息失败"),
		SERVER_ERROR(8008,"服务器错误");
		
		private int code;
		private String message;
		
		private ResCode(int code,String message){
			this.setCode(code);
			this.setMessage(message);
		}

		public int getCode() {
			return code;
		}

		public void setCode(int code) {
			this.code = code;
		}

		public String getMessage() {
			return message;
		}

		public void setMessage(String message) {
			this.message = message;
		}
		
		/**
		 * 根据返回状态码获取异常信息
		 * @param code
		 * @return
		 */
		public static String findResMsgByCode(int code){
		  Optional<String> op = Arrays.stream(ResCode.values()).filter(x->x.getCode()==code).map(ResCode::getMessage).findFirst();
		  if(op.isPresent()){
			  return op.get();
		  }
		  return null;
		}
}